import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class APC here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class APC extends Unidad
{
    int turnosParaDisparar = 0;
    GreenfootSound sonidoDisparo,
                   sonidoExplosion;
                   
    public APC(Color col, boolean humano)
    {
        super(col, humano);
        setImage("apc_"+color.name()+".gif");
        getImage().scale( (int)(getImage().getWidth()*.5), (int)(getImage().getHeight()*.5) );
        vida = 50;
        velocidad = 15;
        sonidoDisparo = new GreenfootSound("machinegun.mp3");
        sonidoExplosion = new GreenfootSound("tank_exploding.wav");
    }
    
    public void act() 
    {
        super.act();
        if( turnosParaDisparar > 0 ) turnosParaDisparar--;
    }
    
    public boolean enRango( Unidad u ){
        return distancia(u) < 200;
    }
    
    protected void apuntar(){
        turnTowards( objetivo.getX(), objetivo.getY() );
    }
    
    public void atacar(){
        apuntar();
        if( turnosParaDisparar == 0 ) {
            turnosParaDisparar = 2;
            Disparo d = new Disparo();
            getWorld().addObject( d, getX(), getY() );
            d.setRotation( getRotation()+3 );
            d.move(25);
            ImpactoBala ib1 = new ImpactoBala();
            getWorld().addObject( ib1, objetivo.getX()+Greenfoot.getRandomNumber(10), objetivo.getY()+Greenfoot.getRandomNumber(10) );
            sonidoDisparo.play();
            objetivo.bajarVida(5);
        }
    }
    
    public void muere(){
        sonidoExplosion.play();
    }
}
